home *** CD-ROM | disk | FTP | other *** search
- /*
- ••••••••••••••••••••
- EncrustImage.c
- David Surovell
-
- this file contains 1 routine BitmapShape_Encrust() that demonstrates
- combining 2 shapes via gx transfer mode. The combination is using
- the 1st shape’s hue and saturation with the 2nd shape’s brightness.
-
- This effect is shown in the 3rd color plate on the inside cover of
- Inside Macintosh: GX Objects
-
- ••••••••••••••••••••
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <QuickDraw.h>
- #include <Windows.h>
-
- #include "graphics types.h"
- #include "graphics errors.h"
- #include "graphics routines.h"
- #include "graphics toolbox library.h"
- #include "graphics libraries.h"
-
- #include "offscreen library.h"
-
-
- void BitmapShape_Encrust(
- gxShape originalShape1,
- gxShape originalShape2,
- gxShape bitmapDest );
- void SetHueTransferMode(
- gxShape targetShape );
- void SetLuminanceTransferMode(
- gxShape targetShape );
- void Shape_GetTransferMode(
- gxShape targetShape,
- gxTransferMode *curXfer );
- void Shape_SetTransferMode(
- gxShape targetShape,
- gxTransferMode *curXfer );
-
-
- void BitmapShape_Encrust(
- gxShape shape1,
- gxShape shape2,
- gxShape bitmapDest )
- {
- gxTransferMode savedXferMode;
-
- if ((shape1 == nil) || (shape2 == nil) || (bitmapDest == nil))
- return;
-
- // Copy 1st shape to destination bitmap.
- CopyToBitmaps( bitmapDest, shape1 );
-
- // Copy 1st shape’s hue data to destination bitmap.
- Shape_GetTransferMode( shape2, &savedXferMode );
- SetHueTransferMode( shape2 );
- CopyToBitmaps( bitmapDest, shape2 );
- Shape_SetTransferMode( shape2, &savedXferMode );
- }
-
-
- /*
- * •••NOTE: this won’t work for picture shapes
- * because picture shape inks are ignored!
- */
- void SetHueTransferMode(
- gxShape targetShape )
- {
- gxTransferMode x;
-
- if (targetShape == nil)
- return;
-
- Shape_GetTransferMode( targetShape, &x );
-
- x.space = gxHSVSpace;
- x.flags = (gxTransferFlag)0;
-
- x.component[0].mode = gxCopyMode;
- x.component[0].flags = 0;
- x.component[0].sourceMinimum = 0x0000;
- x.component[0].sourceMaximum = 0xFFFF;
- x.component[0].deviceMinimum = 0x0000;
- x.component[0].deviceMaximum = 0xFFFF;
- x.component[0].clampMinimum = 0x0000;
- x.component[0].clampMaximum = 0xFFFF;
- x.component[0].operand = 0x0000;
-
- x.component[1].mode = gxCopyMode;
- x.component[1].flags = 0;
- x.component[1].sourceMinimum = 0x0000;
- x.component[1].sourceMaximum = 0xFFFF;
- x.component[1].deviceMinimum = 0x0000;
- x.component[1].deviceMaximum = 0xFFFF;
- x.component[1].clampMinimum = 0x0000;
- x.component[1].clampMaximum = 0xFFFF;
- x.component[1].operand = 0x0000;
-
- x.component[2].mode = gxNoMode;
- x.component[2].flags = 0;
- x.component[2].sourceMinimum = 0x0000;
- x.component[2].sourceMaximum = 0xFFFF;
- x.component[2].deviceMinimum = 0x0000;
- x.component[2].deviceMaximum = 0xFFFF;
- x.component[2].clampMinimum = 0x0000;
- x.component[2].clampMaximum = 0xFFFF;
- x.component[2].operand = 0x0000;
-
- x.component[3].mode = gxNoMode;
- x.component[3].flags = 0;
- x.component[3].sourceMinimum = 0x0000;
- x.component[3].sourceMaximum = 0xFFFF;
- x.component[3].deviceMinimum = 0x0000;
- x.component[3].deviceMaximum = 0xFFFF;
- x.component[3].clampMinimum = 0x0000;
- x.component[3].clampMaximum = 0xFFFF;
- x.component[3].operand = 0x0000;
-
- Shape_SetTransferMode( targetShape, &x );
- }
-
-
- /*
- * •••NOTE: this won’t work for picture shapes
- * because picture shape inks are ignored!
- */
- void SetLuminanceTransferMode(
- gxShape targetShape )
- {
- gxTransferMode x;
-
- if (targetShape == nil)
- return;
-
- Shape_GetTransferMode( targetShape, &x );
-
- x.space = gxHSVSpace;
- x.flags = (gxTransferFlag)0;
-
- x.component[0].mode = gxNoMode;
- x.component[0].flags = 0;
- x.component[0].sourceMinimum = 0x0000;
- x.component[0].sourceMaximum = 0xFFFF;
- x.component[0].deviceMinimum = 0x0000;
- x.component[0].deviceMaximum = 0xFFFF;
- x.component[0].clampMinimum = 0x0000;
- x.component[0].clampMaximum = 0xFFFF;
- x.component[0].operand = 0x0000;
-
- x.component[1].mode = gxNoMode;
- x.component[1].flags = 0;
- x.component[1].sourceMinimum = 0x0000;
- x.component[1].sourceMaximum = 0xFFFF;
- x.component[1].deviceMinimum = 0x0000;
- x.component[1].deviceMaximum = 0xFFFF;
- x.component[1].clampMinimum = 0x0000;
- x.component[1].clampMaximum = 0xFFFF;
- x.component[1].operand = 0x0000;
-
- x.component[2].mode = gxCopyMode;
- x.component[2].flags = 0;
- x.component[2].sourceMinimum = 0x0000;
- x.component[2].sourceMaximum = 0xFFFF;
- x.component[2].deviceMinimum = 0x0000;
- x.component[2].deviceMaximum = 0xFFFF;
- x.component[2].clampMinimum = 0x0000;
- x.component[2].clampMaximum = 0xFFFF;
- x.component[2].operand = 0x0000;
-
- x.component[3].mode = gxNoMode;
- x.component[3].flags = 0;
- x.component[3].sourceMinimum = 0x0000;
- x.component[3].sourceMaximum = 0xFFFF;
- x.component[3].deviceMinimum = 0x0000;
- x.component[3].deviceMaximum = 0xFFFF;
- x.component[3].clampMinimum = 0x0000;
- x.component[3].clampMaximum = 0xFFFF;
- x.component[3].operand = 0x0000;
-
- Shape_SetTransferMode( targetShape, &x );
- }
-
-
- void Shape_GetTransferMode(
- gxShape targetShape,
- gxTransferMode *curXfer )
- {
- gxInk targetInk;
- short i;
-
- if (curXfer == nil)
- return;
-
- targetInk = nil;
- if (targetShape != nil)
- targetInk = GXGetShapeInk( targetShape );
- if (targetInk != nil)
- (void)GXGetInkTransfer( targetInk, curXfer );
- else
- {
- for (i=0; i<4; i++)
- curXfer->component[i].mode = gxNoMode;
- }
- }
-
-
- void Shape_SetTransferMode(
- gxShape targetShape,
- gxTransferMode *curXfer )
- {
- gxInk targetInk;
-
- if ((targetShape == nil) || (curXfer == nil))
- return;
-
- targetInk = GXGetShapeInk( targetShape );
- if (targetInk != nil)
- (void)GXSetInkTransfer( targetInk, curXfer );
- }
-
-
-